package tp.pr5.gui;

import java.util.List;

import javax.swing.JLabel;
import javax.swing.JPanel;

import tp.pr5.Constants;
import tp.pr5.Direction;
import tp.pr5.NavigationObserver;
import tp.pr5.PlaceInfo;
import tp.pr5.RobotEngineObserver;
import tp.pr5.items.InventoryObserver;
import tp.pr5.items.Item;

public class InfoPanel extends JPanel implements RobotEngineObserver, NavigationObserver, InventoryObserver
{
	private static final long serialVersionUID = 1L;
	
	private JLabel label;
	
	/**
	 * Main constructor
	 * 
	 */
	public InfoPanel()
	{
		this.label = new JLabel();
		this.add(label);
	}
	/**
	 * 	The robot engine informs that the communication is over.
	 */
	public void communicationCompleted()
	{
		//empty
	} 
	 
	/**
	 * The robot engine informs that the help has been requested
	 */
	public void communicationHelp(String help)
	{
		//empty
	} 
	
	/**
	 * 	The robot engine informs that the robot has shut down (because it has arrived at the spaceship or it has run out of fuel)
	 */
	public void engineOff(boolean atShip)
	{
		if(atShip)
		{
			this.label.setText(Constants.MESSAGE_FIN_SPACESHIP);
		}
		else
		{
			this.label.setText(Constants.MESSAGE_DIE);
		}
	} 
	 
	/**
	 * 	Notifies that the robot heading has changed
	 */
	public void headingChanged(Direction newHeading)
	{
		//empty
	} 
	 
	/**
	 * 	Notifies that the navigation module has been initialized
	 */
	public void initNavigationModule(PlaceInfo initialPlace, Direction heading)
	{
		//empty
	} 
	 
	/**
	 * 	Notifies that the container has changed
	 * 
	 * @param inventory
	 */
	public void inventoryChange(List<Item> inventory)
	{
		//empty
	} 
	
	/**
	 * 	Notifies that the user requests a SCAN instruction over the inventory.
	 * 
	 * @param collectionDescription
	 */
	public void inventoryScanned(String collectionDescription)
	{
		//empty
	} 
	 
	/**
	 * 	Notifies that an item is empty and it will be removed from the container.
	 * 
	 * @param itemName
	 */
	public void itemEmpty(String itemName)
	{
		this.label.setText(Constants.MESSAGE_EMPTY.replace("{ID}", itemName));
	} 
	 
	/**
	 * 	Notifies that the user wants to scan an item allocated in the inventory
	 * 
	 * @param description
	 */
	public void itemScanned(String description)
	{
		//empty
	} 
	 
	/**
	 * 	Notifies that the place where the robot stays has changed (because the robot picked or dropped an item)
	 * 
	 */
	public void placeHasChanged(PlaceInfo placeDescription)
	{
		//empty
	} 
	 
	/**
	 * 	Notifies that the user requested a RADAR instruction
	 */
	public void placeScanned(PlaceInfo placeDescription)
	{
		//empty
	} 
	 
	/**
	 * 	The robot engine informs that it has raised an error
	 */
	public void raiseError(String msg)
	{
		this.label.setText(msg);
	} 

	/**
	 * 	Notifies that the robot has arrived at a place
	 */
	public void robotArrivesAtPlace(Direction heading, PlaceInfo place)
	{
		//empty
	} 
	 
	/**
	 * 	The robot engine informs that the robot wants to say something
	 */
	public void robotSays(String message)
	{
		this.label.setText(message);
	} 

	/**
	 * 	The robot engine informs that the fuel and/or the amount of recycled material has changed 
	 */
	public void robotUpdate(int fuel, int recycledMaterial)
	{
		this.label.setText(Constants.MESSAGE_UPDATE.replace("{HEALTH}", Integer.toString(fuel)).replace("{SCORE}", Integer.toString(recycledMaterial)));
	}


}
